package com.gujiangbo.application.common.trace.utils;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Date;

import org.apache.commons.lang3.time.FastDateFormat;

public class TraceUtils {

	private static FastDateFormat fdf = FastDateFormat.getInstance("yyMMddHHmmss.SSS");
	public static final String DEFAULT_MS_TIME_FORMAT = "yyMMddHHmmss.SSS";

	public static String convertDate2MSString(Date date) {
		if (null == date) {
			return null;
		}
		return fdf.format(date);
	}

	public static String convertDate2MSString(long time) {
		Date date = new Date(time);
		return fdf.format(date);
	}

	public static int getRandomBySecureRandom() {
		SecureRandom rnd = null;
		try {
			rnd = SecureRandom.getInstance("SHA1PRNG");
		} catch (NoSuchAlgorithmException e) {
			rnd = new SecureRandom();
		}
		return rnd.nextInt();
	}

}
